package com.easwift.qsp.das;

import cn.hutool.core.date.DateUtil;
import com.easwift.qsp.util.DataSourceUtils;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class Test {

	public static Set<Long> socketThreadSet = new HashSet<>();

	public static void main(String[] args) throws IOException {

		// 不同端口处理不同类型设备数据
		// TODO port从平台中读取
		//1.建立ServerSocket对象，监听绑定端口
		ServerSocket dtuServerSocket = new ServerSocket(8090);
		//ServerSocket cjyServerSocket = new ServerSocket(8091);
		//ServerSocket qjyServerSocket = new ServerSocket(8092);
		//new ServerSocketThread(qjyServerSocket).start();
		//new ServerSocketThread(cjyServerSocket).start();
		new ServerSocketThread(dtuServerSocket).start();

	}


/*public static void main(String[] args) {
	File f=new File("C:\\picfile");
	traverseFile(f);
}
	//遍历所有的文件
	static void traverseFile(File f){

		File[] files=f.listFiles();

		for (File fi:files){
			//如果是目录
			if (fi.isDirectory()){
				//System.out.println(fi);
				//递归
				traverseFile(fi);
			}
			else{
				//如果是文件
				// 不打印隐藏文件
				if (!fi.isHidden())
				{
					String filename=fi.getName();
					System.out.println("文件的绝对路径："+fi);
					//判断一下，只有当文件名符合条件才可以执行
					if(filename.length()>=46){
						//分割字符串
						String[] s = filename.split("_");
						Date date = DateUtil.parse(s[2], "yyyyMMddHHmmssSSS");
						System.out.println(date.toString());

						//保存到数据库中
						String sql = String.format("INSERT INTO tb_device_xgdata(address,value,imageurl,createtime)" +
								"SELECT %s,1,%s,%s FROM dual" +
								" WHERE NOT EXISTS(SELECT imageurl FROM tb_device_xgdata where imageurl=%s)","'"+s[1]+"'","'file/"+filename+"'","'"+date.toString()+"'","'file/"+filename+"'");
						DataSourceUtils.getJdbcTemplate().execute(sql);
					}

				}
			}

		}

	}*/

}
